#include "front/text_normalize.h"

using namespace std;
using namespace ppspeech;

const wregex mcWregexWavyline(L"((-?)(\\d+)(\\.\\d+)?)(~(-?)(\\d+)(\\.\\d+)?)+");

// 范围，例如：60~90 --> 六十到九十
void TextNormalizer::TnReWavyline(wstring* fpInWsentence, const LanguageEnum fcInLanguage)
{
	wsmatch tWsmatch;

	while (regex_search(*fpInWsentence, tWsmatch, mcWregexWavyline)) {
		string tStrWavyline = wstring2utf8string(tWsmatch[0]);		//匹配到波浪线的字符串
		vector<string> tItemWavyline = StrSplit(tStrWavyline, "~");

		vector<wstring> tVecNextWords = GetWstrPositionNextWords(*fpInWsentence, tWsmatch.position(1) + tWsmatch.length(1), 1, LANG_ZH);
		wstring tUnit = (tVecNextWords.size() > 0 ? tVecNextWords[0] : L"");	//单位

		string tStrReplace;
		if(tUnit == L"年") {
			for(int i=0; i<tItemWavyline.size(); i++) {
				if(i > 0)  {
					tStrReplace += (fcInLanguage==LANG_EN) ? " to " : "至";
				}
				tStrReplace += ReplaceMethod(vector<string>{tItemWavyline[i]}, (fcInLanguage==LANG_EN)?RME_en_year:RME_zh_digit_yi1);
			}
		}
		else {
			//__~__  --> __到__
			tStrReplace = ReplaceMethod(tItemWavyline, (fcInLanguage==LANG_EN)?RME_en_range:RME_zh_range);
		}

		WstrReplacePosition(fpInWsentence, tWsmatch.position(0), tWsmatch.length(0), utf8string2wstring(tStrReplace));
	}
}
